

<div class="row">
    <div class="col-lg-12">
        <h1 class="page-header"><?php echo __('List of cities'); ?></h1>
    </div>
               
</div>
<!-- /.row -->
            <div class="row">
                <div class="col-lg-12">
                <p>
                    <a class="btn btn-success" href="<?php echo $this->Html->url(array('action' => 'add')); ?>"><?php echo __('Add City '); ?><i class="fa fa-plus"></i></a>
               </p>


                    <!-- Form d'ajout -->

                     <div class="panel panel-default">
                        <div class="panel-heading">
                            <?php echo __('Search of city'); ?>
                        </div>
                        <div class="panel-body">
                            <div class="row">
                                <div class="col-lg-6">
    <?php echo $this->Form->create('City',array('type'=>'post', 'action'=>'searchByCity','id'=>'saveForm','role'=>'form')); ?>

                                        <div class="form-group">
                                            <label><?php echo __('Country'); ?></label>
                                            <?php echo $this->Form->select('country_id', $countries, array('class' => 'form-control', 'required'=> 'required', 'empty' =>'Select Country')); ?>
                                        </div>
                                </div>
                                <!-- /.col-lg-6 (nested) -->
                                <div class="col-lg-6">
                                    <div class="form-group">
                                            <label><?php echo __('City'); ?></label>
                                            <?php echo $this->Form->input('label',array('class'=>'form-control','id'=>'city','label'=> false, 'type' =>'text', 'placeholder'=>'Search by city'));?>
                                    </div>
                                    
                                </div>
                            
                         <?php echo $this->Form->end(); ?>

                            </div>
                            <!-- /.row (nested) -->
                        </div>
                        <!-- /.panel-body -->
                    </div> 
                    <!-- /.panel -->
                          
<div class="panel panel-default">
    <div class="panel-heading">
                        	<?php echo __('List of cities'); ?>
    </div>
                        <!-- /.panel-heading -->
     <div class="panel-body">
            <div class="table-responsive" id='serachBycity' >
                    <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                    <thead>
                                        <tr>
                                           <th> <?php echo $this->Paginator->sort('id'); ?></th>

                                            <th><?php echo $this->Paginator->sort('City'); ?></th>
                                            
                                            <th><?php echo __('Action'); ?></th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        	<?php foreach ($cities as $city): ?>
                                        
                                        <tr class="gradeA">
                                     <td><?php echo h($city['City']['id']); ?>&nbsp;</td>
                                        <td><?php echo h($city['City']['label']); ?>&nbsp;</td>
                                            <td>
                                            	<?php echo $this->Html->link(__('View'), array('action' => 'view', $city['City']['id'])); ?>
			<?php echo $this->Html->link(__('Edit'), array('action' => 'edit', $city['City']['id'])); ?>
			<?php echo $this->Form->postLink(__('Delete'), array('action' => 'delete', $city['City']['id']), null, __('Are you sure you want to delete # %s?', $city['City']['id'])); ?>
                                            </td>
                                           
                                        </tr>
                                       
                                        <?php endforeach; ?>
                                    </tbody>
                                </table>
                                <?php echo  $this->element('paginate'); ?>
    </div>
                        <!-- /.panel-body -->
</div>
</div>
</div>







<script>
$("#city").keyup(function(){

                var city=$(this).val();
                var url = "cities/searchByCity/"+city;
                $("#serachBycity").html('<div style="padding-top:20px;padding-bottom:20px;text-align:center;"><img src="img/load.gif"></div>');
                $.get(url, function(data) {
                     //

                    $("#serachBycity").html(data);
                });
            });






/*$("#city").keyup(function()
{
   alert($('#city').val());
    });
/*$("#city").keyup(function()
{
     var city= $('#city').val();

     
    if(city!="")
    {   

    $('#dataTables-example').remove(); 
        jQuery.ajax(
        {
            url:'searchByCity/'+city ,
            context: document.body,
            success: function(data)
            {
                if (data!=0) 
                {
                    var citys = jQuery.parseJSON(data);
                    $.each(citys, function(i, item) {
                       $('#dataTables-example').append("<table> <tr><td></td></tr></table>"); 
                   
  });
                    
                } 
             }
        });
    }        
    });
*/
</script>


<?php
/*$this->Js->get('#city')->event('keyup', 
  $this->Js->request(array(
    'controller'=>'cities',
    'action'=>'searchByCity'
    ), array(
    'update'=>'#erachBycity',
    'async' => true,
    'method' => 'post',
    'dataExpression'=>true,
    'data'=> $this->Js->serializeForm(array(
      'isForm' => true,
      'inline' => true
      ))
    ))
  );*/
  
?>









